package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.entity.User;
import com.khyr.service.UserService;
import com.khyr.vo.R;
import com.khyr.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 宋一恒
 * @version 1.0
 */
@RestController
@RequestMapping("/systemManager/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/findUserByCond")
    //查询用户
    public R<Page<User>> findUserByCond(@RequestBody UserVo userVo) {


        return userService.findUserByCond(userVo);
    }

    @PostMapping("/addUser")
    //添加用户
    public R<Integer> addUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    @DeleteMapping("/deleteUserByIds/{ids}")
    //删除
    public R<Integer> deleteUserByIds(@PathVariable List<Long> ids) {
        return userService.deleteUserByIds(ids);
    }

    @PostMapping("/updateUser")
    //修改用户
    public R<Integer> updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    //根据id查询用户
    @PostMapping("/getUserById/{id}")
    public R<User> getUserById(@PathVariable Long id) {
        return userService.getUserById(id);
    }

    //重置密码
    @PostMapping("/resetPwd/{userIds}")
    public R<Integer> resetPwd(@PathVariable List<Long> userIds) {
        return userService.resetPwd(userIds);
    }
//    检查电话号是否重复
    @GetMapping("/userPhone/{phone}")
    public R<Integer> userPhone(@PathVariable String phone) {
        return userService.userPhone(phone);
    }
    //提供密码的重置密码
    @PostMapping("/resetPwd1/{userIds}/{password}")
    public R<Integer> resetPwd1(@PathVariable Long userIds, @PathVariable String password) {
        return userService.resetPwd1(userIds,password);
    }

    //根据id查询医生姓名
    @PostMapping("/getdocNameById/{valueId}")
    public R<String> getdocNameById(@PathVariable Long valueId) {
        return userService.getdocNameById(valueId);
    }
}
